package com.studentapp.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.studentapp.R;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {

    private Toolbar toolbar_login;
    private EditText ed_username;
    private EditText ed_email;
    private EditText ed_tel;
    private Spinner sp_1;
    private Spinner sp_2;
    private EditText ed_password1;
    private EditText ed_password2;
    private Button btn_register;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initView();
    }

    private void initView() {
        toolbar_login = (Toolbar) findViewById(R.id.toolbar_login);
        ed_username = (EditText) findViewById(R.id.ed_username);
        ed_email = (EditText) findViewById(R.id.ed_email);
        ed_tel = (EditText) findViewById(R.id.ed_tel);
        sp_1 = (Spinner) findViewById(R.id.sp_1);
        sp_2 = (Spinner) findViewById(R.id.sp_2);
        ed_password1 = (EditText) findViewById(R.id.ed_password1);
        ed_password2 = (EditText) findViewById(R.id.ed_password2);
        btn_register = (Button) findViewById(R.id.btn_register);

        btn_register.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_register:

                break;
        }
    }

    private void submit() {
        // validate
        String username = ed_username.getText().toString().trim();
        if (TextUtils.isEmpty(username)) {
            Toast.makeText(this, "username不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String email = ed_email.getText().toString().trim();
        if (TextUtils.isEmpty(email)) {
            Toast.makeText(this, "email不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String tel = ed_tel.getText().toString().trim();
        if (TextUtils.isEmpty(tel)) {
            Toast.makeText(this, "tel不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String password1 = ed_password1.getText().toString().trim();
        if (TextUtils.isEmpty(password1)) {
            Toast.makeText(this, "password1不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        String password2 = ed_password2.getText().toString().trim();
        if (TextUtils.isEmpty(password2)) {
            Toast.makeText(this, "password2不能为空", Toast.LENGTH_SHORT).show();
            return;
        }

        // TODO validate success, do something


    }
}
